package com.itai.controller;

import com.itai.assistant.MedicalAgent;
import com.itai.bean.ChatForm;
import io.swagger.v3.oas.annotations.Operation;

import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("/medical")
@Tag(name = "MedicalAi")
public class MedicalController {
    @Autowired
    private MedicalAgent medicalAgent;
    @Operation(summary = "对话")
    @PostMapping(value = "/chat", produces = "text/stream;charset=utf-8")
    public Flux<String> chat(@RequestBody ChatForm chatForm) {

            Long memoryId = chatForm.getMemoryId();
            System.out.println("memoryId: " + memoryId + ", 类型: " + (memoryId == null ? "null" : memoryId.getClass()));
            if (memoryId == null) {
                throw new IllegalArgumentException("memoryId 为 null，请检查前端请求格式");
            }
            return medicalAgent.chat(memoryId, chatForm.getMessage());

    }
}
